# -*- coding: UTF-8 -*-
"""
@auth:buxiangjie
@date:2023/5/5 17:50
@describe: 
"""
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.jobstores.redis import RedisJobStore
from apscheduler.executors.pool import ProcessPoolExecutor
from runcase_statistics.get_sql_data import Statistics
from app.common.common_func import Common

REDIS_DB = {
	"db": 15,
	"host": "172.17.205.187",
	"port": "9917",
	"password": "j_dR29nz1Z"
}

interval_task = {
	# 配置存储器
	"jobstores": {
		# 使用redis进行存储
		"default": RedisJobStore(**REDIS_DB)
	},
	# 配置执行器
	"executors": {
		# 使用进程池调度
		"default": ProcessPoolExecutor()
	},
	# 创建job时的默认参数
	"job_defaults": {
		"coalesce": False,
		"max_instances": 1
	}
}


def test_case_daily_count(job_id="test_case_daily_count"):
	Statistics(Common.get_new_time("before", "days", 1).split(" ")[0]).daily_count()


scheduler = AsyncIOScheduler(**interval_task)
scheduler.add_job(test_case_daily_count, "cron", hour=1, id="test_case_daily_count", replace_existing=True)
